home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
program
/
progem.lzh
/
wind7.prf
< prev
next >
Wrap
Text File
|
1987-06-23
|
18KB
|
406 lines
.!****************************************************************************
.!
.! ANTIC PUBLISHING INC., COPYRIGHT 1985. REPRINTED BY PERMISSION.
.!
.! ** Professional GEM ** by Tim Oren
.!
.! Proff File by ST enthusiasts at
.! Case Western Reserve University
.! Cleveland, Ohio
.! uucp : decvax!cwruecmp!bammi
.! csnet: bammi@case
.! arpa : bammi%case@csnet-relay
.! compuserve: 71515,155
.!
.!****************************************************************************
.!
.!
.!****************************************************************************
.!
.! Begin Part 7
.!
.!****************************************************************************
.!
.PART VII Menu Structures
.SH HAPPY NEW YEAR
This is article number seven in the ST
PRO GEM series, and the first for 1986. In this installment,
I will be discussing GEM menu structures and how to use them
in your application. There is also a short Feedback
response section. You will find the download file containing
the code for this column in the file GEMCL7.C in DL3 of the
ATARI16 SIG (PCS-58).
.SH MENU BASICS
In ST GEM, the menu consists of a bar
across the top of the screen which displays several sub-menu
titles. Touching one of the titles causes it to highlight,
and an associated "drop-down" to be drawn directly below on
the screen. This drop-down may be dismissed by moving to
another title, or by clicking the mouse off of the drop-down.
.PP
To make a selection, the mouse is moved over the
drop-down. Each valid selection is highlighted when the
mouse touches it. Clicking the mouse while over one of
these selections picks that item. GEM then undraws the
drop-down, and sends a message to your application giving the
object number of the title bar entry, and the object number
of the drop-down item which were selected by the user. The
selected title entry is left highlighted while your code
processes the request.
.SH MENU STRUCTURES
The data structure which defines a GEM
menu is (surprise!) an object tree, just like the dialogs and
panels which we have discussed before. However, the
operations of the GEM menu manager are quite different from
those of the form manager, so the internal design of the menu
tree has some curious constraints.
.PP
The best way to understand these constraints is to look
at an example. The first item in the download is the object
structure (only) of the menu tree from the GEM Doodle/Demo
sample application.
.PP
The ROOT of a menu tree is sized to fit the entire
screen. To satisfy the visual hierarchy principle (see
article #5), the screen is divided into two parts: THE BAR,
containing the menu titles, and THE SCREEN, while contains
the drop-downs when they are drawn. Each of these areas is
defined by an object of the same name, which are the only two
objects linked directly below the ROOT of a menu tree. You
will notice an important implication of this structure: The
menu titles and their associated drop-downs are stored in
entirely different subtrees of the menu!
.PP
While examining THE BAR in the example listing, you may
notice that its OB_HEIGHT is very large (513). In
hexadecimal this is 0x0201. This defines a height for THE
BAR of one character plus two pixels used for spacing. THE
BAR and its subtree are the only objects which are drawn on
the screen in the menu's quiescent state.
.PP
The only offspring object of THE BAR is THE ACTIVE. This
object defines the part of THE BAR which is covered by menu
titles. The screen rectangle belonging to THE ACTIVE is used
by the GEM screen manager when it waits for the mouse to
enter an active menu title. Notice that THE ACTIVE and its
offspring also have OB_HEIGHTs with pixel residues.
.PP
The actual menu titles are linked left to right in order
below THE ACTIVE. Their OB_Xs and OB_WIDTHs are arranged so
that they completely cover THE ACTIVE. Normally, the title
objects are typed G_TITLE, a special type which assures that
the title bar margins are correctly drawn.
.PP
THE SCREEN is the parent object of the drop-down boxes
themselves. They are linked left to right in an order
identical with their titles, so that the menu manager can
make the correct correspondence at run-time. The OB_X of
each drop-down is set so that it is positioned below its
title on the screen.
.PP
Notice that it is safe to overlap the drop-downs within a
menu, since only one of them will be displayed at any time.
There is one constraint on the boxes however: They must be
no greater than a quarter screen in total size. This is the
size of the off-screen blit buffer which is used by GEM to
store the screen contents when the drop-down is drawn. If
you exceed this size, not all the screen under the drop-down
will be restored, or the ST may crash!
.PP
The entries within a drop-down are usually G_STRINGs,
which are optimized for drawing speed. The rectangles of
these entries must completely cover the drop-down, or the
entire drop-down will be inverted when the mouse touches an
uncovered area! Techniques for using objects other than
G_STRINGs are discussed later in this column.
.PP
The first title and its corresponding drop-down are
special. The title name, by custom, is set to DESK. The
drop-down must contain exactly eight G_STRING objects. The
first (again by custom) is the INFO entry, which usually
leads to a dialog displaying author and copyright information
for your application. The next is a separator string of
dashes with the DISABLED flag set. The following six objects
are dummy strings which GEM fills in with the names of desk
accessories when your menu is loaded.
.PP
The purpose of this description of menu trees is to give
you an understanding of what lies "behind the scenes" in the
next section, which describes the run-time menu library
calls. In practice, the Resource Construction Set provides
"blank menus" which include all of the required elements, and
it also enforces the constraints on internal structure. You
only need to worry about these if you modify the menu tree
"on-the-fly".
.SH USING THE MENU
once you have loaded the application's
resource, you can ask the AES to install your menu. You must
first get the address of the menu tree within the resource
using:
.FB rsrc_gaddr()
rsrc_gaddr(R_TREE, MENUTREE, &ad_menu);
.FE
assuming that MENUTREE is the name you gave the menu in the
RCS, and that ad_menu is a LONG which will receive the
address. Then you call the AES to establish the menu:
.FB menu_bar()
menu_bar(ad_menu, TRUE);
.FE
At this point, the AES draws your menu bar on the screen and
animates it when the user moves the mouse into the title
area.
.PP
The AES indicates that the user has made a menu selection
by sending your application a message. The message type is
MN_SELECTED, which will be stored in msg[0], the first
location in the message returned by evnt_multi().
.PP
The AES also stores the object number of the selected
menu's title in msg[3], and the object number of the
selected menu item in msg[4]. Generally, your application
will process menu messages with nested C switch statements.
The outer switch will have one case for each menu title, and
the inner switch statements will have a case for each entry
within the selected menu. (This implies that you must give a
name to each title and to each menu entry when you create the
menu in the RCS.)
.PP
After the user has made a menu selection, the AES leaves
the title of the chosen menu in reverse video to indicate
that your application is busy processing the message. When
you done with whatever action is indicated, you need to
return the title to a normal state. This is done with
.FB menu_tnormal()
menu_tnormal(ad_menu, msg[3], TRUE);
.FE
.sp 1
.ce 1
(Remember that msg[3] is the title's object number.)
.sp 1
When your application is ready to terminate, it should
delete its menu bar. Do this with the call:
menu_bar(ad_menu, FALSE);
.SH GETTING FANCY
The techniques above represent the bare
minimum to handle menus. In most cases, however, you will
want your menus to be more "intelligent" in displaying the
user's options. For instance, you can prevent many user
errors by disabling inappropriate choices, or you c